<template>
  <div class="newslist">
    <van-loading type="spinner" v-if="isSpinnerShow"></van-loading>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-card @click="godetail(item.id)" v-for="item in NewsList" :key="item.id" :title="item.title" :thumb="item.img_url">
        <template slot="num">点击了：{{item.click}}</template>
        <template slot="price">发表时间：{{item.add_time | formatDate}}</template>
      </van-card>
    </van-pull-refresh>
  </div>
</template>
<script>
export default {
  created() {
    this.getNewsList();
  },
  data() {
    return {
      NewsList: [],
      count: 0,
      isLoading: false,
      isSpinnerShow: true
    };
  },
  methods: {
    async getNewsList() {
      const { data: res } = await this.$http.get("/api/getnewslist");
      if (res.status != 0) return this.$toast.error("请求数据失败");
      this.NewsList = res.message;
      this.isSpinnerShow = false;
    },
    onRefresh() {
      this.getList();
    },
    godetail (id) {
      this.$router.push('/newsdetail/'+id)
    }
  }
};
</script>
<style scoped lang="less">
.van-loading {
  text-align: center;
}
</style>